<template>
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled='isOpen'>确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { findPartInfo,orderChoose } from '@/api/partsmanage/aduitOrder/orderProxyReport';
import { findPartTypeList } from '@/api/partsmanage/partinfos/partInfoManage/index';


export default {
  props: {
    orderType: {
      type: String | Number,
      default: ''
    }
  },
  data(){
    return{
      topFilterList:this.createdFrom(),
      columns:this.createdTable(),
      fetchParams:{
        orderType: this.orderType
      },
      fetchApi:orderChoose,
      selectList:[],
      partTypeList:[],
      isOpen:true,
    }
  },
  mixins:[dictionary],
  created(){
    findPartTypeList().then(res =>{
      this.partTypeList = res.data;
      this.topFilterList.find(x=>x.fieldName=='partType').itemList = this.partTypeList;
    });
  },
  methods:{
    createdFrom(){
      return [
        {
          type: 'INPUT',
          label: '备件代码',
          fieldName: 'partNo',
          placeholder: '请选择',
        },
        {
          type: 'INPUT',
          label: '备件名称',
          fieldName: 'partName',
          placeholder: '请选择',
        },
        {
          type: 'SELECT',
          label: '备件分类',
          fieldName: 'partType',
          itemList: [],
          placeholder: '请选择...',
        },
      ]
    },
    createdTable(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '备件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '备件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '备件分类',
          dataIndex: 'partTypeName',
          sorter: true
        },
        {
          title: '物料组',
          dataIndex: 'material',
          sorter: true,
          align:"center",
          dictItems: this.createDictList('3054')
        },
        {
          title: '订购单价',
          dataIndex: 'partPrice',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '销售包装量',
          dataIndex: 'minPackageNum',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '计量单位',
          dataIndex: 'partUnit',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '适用车型',
          dataIndex: 'partModel',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ]
    },
    changeHandle(val){
      this.isOpen=true;
      this.fetchParams=Object.assign({},this.fetchParams,val)
    },
    closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        this.$emit('close',this.selectList)
      }
    },
    selectChangeHandle(val){
      if(val.length>0){
        this.selectList=val;
        this.isOpen=false;
      }else{
        this.isOpen=true;
        this.selectList=[]
      }

    }
  },

}
</script>
